package 泛型.深入理解泛型;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: algorithm
 * @description: 验证类型擦除
 * @author: 陈恩涛
 * @create: 2021-12-20 17:32
 **/
public class ValidateTypeErasure {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        List<String> stringArrayList = new ArrayList<>();
        List<Integer> integerArrayList = new ArrayList<>();
        //原始类型相等
        System.out.println(stringArrayList.getClass() == integerArrayList.getClass());

        //通过其他反射添加其它类型
        integerArrayList.add(1);
        integerArrayList.getClass().getMethod("add",Object.class).invoke(integerArrayList,"asd");
        for (int i = 0; i < integerArrayList.size(); i++) {
            System.out.println(integerArrayList.get(i));
        }
    }
}
